package com.gxa.p2p.controller;

import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Redpac;
import com.gxa.p2p.pojo.Redpaclog;
import com.gxa.p2p.service.RedPacService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2021-10-26 10:18
 */
@CrossOrigin
@RequestMapping("/redPac")
@Api("红包控制层")
@RestController
public class RedPacController {

    @Autowired
    RedPacService service = null;

    /**
     * 饶贵钢
     * @param name
     * @param type
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/findRedPac")
    @ApiOperation("查询红包")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "红包名字",required = false,dataType = "String"),
            @ApiImplicitParam(name = "type",value = "红包类型",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map findRedPac(@RequestParam("name") String name,
                          @RequestParam("type") String type,
                          @RequestParam("page") Integer page,
                          @RequestParam("size") Integer size
                        ){
        List<Redpac> redPac = service.findRedPac(name, type, page, size);
        Integer redPacCount = service.findRedPacCount(name, type, page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(redPac);
        jsonResult.put("count",redPacCount);
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * @param redpac
     * @return
     */
    @PostMapping("/addRedPac")
    @ApiOperation("新增红包")
    @ApiImplicitParam(name = "redPac",value = "红包详情信息",required = true,paramType = "body")
    public Map addRedPac(Redpac redpac){
        service.addRedPac(redpac);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("添加成功");
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * @param invPhone
     * @param invName
     * @param name
     * @param userOrigin
     * @param colType
     * @param state
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/findRedPacLogByPage")
    @ApiOperation("查询红包获取记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "invPhone",value = "投资人手机",required = false,dataType = "String"),
            @ApiImplicitParam(name = "invName",value = "投资人名字",required = false,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "红包名称",required = false,dataType = "String"),
            @ApiImplicitParam(name = "userOrigin",value = "用户来源",required = false,dataType = "String"),
            @ApiImplicitParam(name = "colType",value = "获取方式",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state",value = "状态",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "int")
    })
    public Map findRedPacLogByPage(@RequestParam("invPhone") String invPhone,
                                   @RequestParam("invName") String invName,
                                   @RequestParam("name") String name,
                                   @RequestParam("userOrigin") String userOrigin,
                                   @RequestParam("colType") String colType,
                                   @RequestParam("state") String state,
                                   @RequestParam("page") Integer page,
                                   @RequestParam("size") Integer size
                                   ){
        List<Redpaclog> redPacLogByPage = service.findRedPacLogByPage(invPhone, invName, name, userOrigin, colType, state, page, size);
        Integer redPacLogCount = service.findRedPacLogCount(invPhone, invName, name, userOrigin, colType, state, page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(redPacLogByPage);
        jsonResult.put("count",redPacLogCount);
        return jsonResult.getDataMap();
    }

    /**
     * 饶贵钢
     * @return
     */
    @PostMapping("/findAllRedPac")
    @ApiOperation("查询所有红包且不分页")
    @ApiImplicitParam(name = "name",value = "红包名称",required = false,paramType = "String")
    public Map findAllRedPac(@RequestParam("name") String name){
        List<Redpac> redPac = service.findRedPac(name, null, null, null);
        Integer redPacCount = service.findRedPacCount(name, null, null, null);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(redPac);
        jsonResult.put("count",redPacCount);
        return jsonResult.getDataMap();
    }
}
